/**
 * 定义站点地图实时数据模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.sw.stationMap.mapManager', ['itfreer',
                                                                        'water.common.publishSubscribe',
                                                                        'water.apps.common.stationMap.stationMapRealDataManager',
                                                                        'water.common.esriMapSearch',
	                                                                    'water.entity.district']);
		
	module.controller('mapController',function($gisObject,$scope,$districtService,$pubSubService,$esriMapSearchService,$controller){

		/**
		 * 继承地图实时数据
		 */
		var control = $controller("commonStationMapRealDataManagerController",{$scope:$scope});
		
		/**
		 * 政区面板是否显示
		 */
		$scope.areaShow = false;
		
		/**
		 * 选中的政区
		 */
		$scope.selectArea = "深圳市";

		/**
		 * 地图实时数据上显示的参数映射
		 */
		$scope.pollToList =[{name:"001",parmName:"PH"},{name:"015",parmName:"总有机碳"},{name:"011",parmName:"CODcr"},{name:"060",parmName:"氨氮"},{name:"101",parmName:"总磷"},{name:"phe",parmName:"挥发酚"},
		                     {name:"028",parmName:"总镍"},{name:"023",parmName:"总铬"},{name:"031",parmName:"总锰"},{name:"065",parmName:"总氮"},{name:"phtem",parmName:"水温"}];
		
		/**
		 * 政区开关点击事件
		 */
		$scope.onAreaShowClick = function(){
			$scope.areaShow = !$scope.areaShow;
		}
		
		/**
		 * 政区选择事件
		 */
		$scope.onAreaChange = function(area){
			$scope.areaShow = !$scope.areaShow;
			$scope.selectArea = area.v;
			var extent = new esri.geometry.Extent(area.MINX,area.MINY,area.MAXX,area.MAXY,$gisObject.map.spatialReference);
			extent = extent.expand(1.1);
			$gisObject.map.setExtent(extent);
			$gisObject.map.infoWindow.hide();
			$pubSubService.publish("mapAreaChange",area);
			
			var mapQueryStr = "";
			
			if(area.NAME === '深圳市'){
				mapQueryStr = " 1 = 1 ";
			}
			else{
				mapQueryStr = "SDE.qx.XIANNAME='"+area.NAME+"'"
			}
			$esriMapSearchService.searchMapServiceSingle('qhhf',mapQueryStr);
		}
		
		/**
		 * 加载政区数据
		 */
		function _initArea(){
			$districtService.getDistrictDomain().then(function(data){
				$scope.area = data.qu;
			});
		}
		_initArea();
	});
}(window, angular));


